home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / DA / P / PCalculator.cpt / CalcDA sources / CalcDA_FuncStack.c < prev    next >
Text File  |  1990-07-06  |  2KB  |  96 lines

  1. /*
  2.  * CalcDA_FuncStack.c for the Programmer's Calculator project 
  3.  * 
  4.  * Copyright 1990, Peter Ohler 
  5.  * 
  6.  * All Rights Reserved 
  7.  * 
  8.  * The Programmer's Calculator and the source code are shareware.  That means
  9.  * they are not free.  If you use either the source or the calculator then
  10.  * send $5 or $10 (whatever you feel its worth) to the address that follows.
  11.  * The source and calculator can be distributed for free.  Prior to any sale
  12.  * of either the source code or the calculator my permission must be
  13.  * obtained.  This includes sales by shareware distribution houses that sell
  14.  * shareware.  
  15.  * 
  16.  * Peter Ohler 
  17.  * 
  18.  * 3184 Rohrer Drive, Lafayette CA 94549 
  19.  * 
  20.  * (415) 284-7828 
  21.  * 
  22.  * ***************************************************************************
  23.  * 
  24.  * The functions that the user specifies using the button on the calculator
  25.  * are not always executed as soon as they are hit.  Functions such as +, - ,
  26.  * *, etc.  are put on a stack and executed when every a function of lower
  27.  * presedence is entered.  This file contains the functions that manage the
  28.  * stack.  
  29.  */
  30.  
  31. #include "CalcDA.h"
  32.  
  33. /*
  34.  * ***************************************************************************
  35.  * prototypes 
  36.  */
  37. IntFunc    PopFuncStack(void);
  38. int    PushFuncStack(IntFunc func);
  39. void    ClearFuncStack(void);
  40.  
  41. /*
  42.  * ***************************************************************************
  43.  * variables 
  44.  */
  45.  
  46. IntFunc    funcPending[] = { 0L, 0L, 0L, 0L, 0L};
  47. int    funcPendingLen = sizeof funcPending / sizeof(funcPending[0]);
  48.  
  49. /*
  50.  * ***************************************************************************
  51.  * functions 
  52.  */
  53. /*
  54.  * I don't think these functions need much explanation.  
  55.  */
  56. IntFunc
  57. PopFuncStack()
  58. {
  59.     IntFunc    top;
  60.     int    i;
  61.     
  62.     top = *funcPending;
  63.     for (i = 1; i < funcPendingLen; i++) {
  64.         funcPending[i - 1] = funcPending[i];
  65.     }
  66.     funcPending[funcPendingLen - 1] = 0L;
  67.     return top;
  68. }
  69.  
  70. int
  71. PushFuncStack(func)
  72.     IntFunc    func;
  73. {
  74.     int    i;
  75.  
  76.     if (0L != funcPending[funcPendingLen - 1])
  77.         return -1;
  78.  
  79.     for (i = funcPendingLen - 1; i > 0; i--) {
  80.         funcPending[i] = funcPending[i - 1];
  81.     }
  82.     *funcPending = func;
  83.     return 0;
  84. }
  85.  
  86. void
  87. ClearFuncStack()
  88. {
  89.     int    i;
  90.  
  91.     for (i = 0; i < funcPendingLen; i++) {
  92.         funcPending[i] = 0L;
  93.     }
  94. }
  95.  
  96.